// pages/logistics/logistics.js
import {queryArticle} from "../../api/article";
import {queryAfterOrderByPage} from "../../api/claim";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        queryFormData: {
            pageSize: 10,
            pageNum: 1,
            dealType: 'send'
        },
        datalist: [],
        loading: true,
        noData: false,
        isLastPage: false,
        loadingFailed: false,
    },

    /**
     * 跳转logisticsDetail页面
     */
    logisticsDetail(event) {
        wx.navigateTo({
            url: '/pages/logisticsAddInfo/logisticsAddInfo',
            success: function (res) {
                res.eventChannel.emit('acceptDataFromOpenerPage', {id: event.currentTarget.dataset.id})
            }
        })
    },
    /**
     * 跳转logisticsAdd页面
     */
    logisticsAdd() {
        wx.navigateTo({
            url: `/pages/logisticsAdd/logisticsAdd`
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // this.queryByPage();
    },

    queryByPage() {
        var that = this;
        wx.showLoading({
            title: '加载中',
        })
        queryAfterOrderByPage(this.data.queryFormData).then(res => {
            wx.hideLoading();
            if (!res.data.isLastPage) {
                that.data.isLastPage = false
            } else {
                that.data.isLastPage = true
            }
            that.data.pageNum += 1;
            that.setData({
                datalist: that.data.datalist.concat(res.data.list)
            })
            if (that.data.datalist.length == 0) {
                that.setData({
                    noData: true
                })
            }
        }).catch((e) => {
            wx.hideLoading();
            this.setData({
                loadingFailed: true
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        if (!this.data.reflush) {
            this.setData({
                datalist: [],
                pageSize: 10,
                pageNum: 1,
            })
            //查询寄件给尚驰的工单
            this.queryByPage();
        }
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({
            reflush: false
        })
    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
